package com.anonymous.util;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Logger;




public class LoggerUtils {
	//private String LOG_PATH = "d:\\LOGTEST\\test_server.txt";
	private static String LOG_PATH = "audit.log";
	//private static String LOG_PATH = "d:\\LOGTEST\\audit.log";
	
	private static Logger logger = Logger.getLogger(LogFormatter.class.getName());
	private static LogFormatter formatter = new LogFormatter();
     // Create console handler and file handler to write log message to console and file
    //private static ConsoleHandler handler = new ConsoleHandler();
	private static FileHandler fileHandler =  null;
	
	public LoggerUtils(){
		
		logger = Logger.getLogger(LogFormatter.class.getName());
	    logger.setUseParentHandlers(false);
			  
	    formatter = new LogFormatter();
	    // Create console handler and file handler to write log message to console and file
	   // handler = new ConsoleHandler();
		try {
			fileHandler = new FileHandler(LOG_PATH,true);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		// Set format of log to handler
	    //handler.setFormatter(formatter);
	    fileHandler.setFormatter(formatter);
	
	    //logger.addHandler(handler);
	    logger.addHandler(fileHandler);
	
	}
	
	public static void logIt2(String message){	    
		try {
		
	    Logger logger = Logger.getLogger(LogFormatter.class.getName());
	    logger.setUseParentHandlers(false);
			  
	    LogFormatter formatter = new LogFormatter();
	    // Create console handler and file handler to write log message to console and file
	    ConsoleHandler handler = new ConsoleHandler();
		FileHandler fileHandler = new FileHandler(LOG_PATH,true);
	
		// Set format of log to handler
	    handler.setFormatter(formatter);
	    fileHandler.setFormatter(formatter);
	
	    logger.addHandler(handler);
	    logger.addHandler(fileHandler);
	    
	    //Write log by define severity.
	    logger.info("Example of creating custom formatter.");
	    logger.warning("A warning message.");
	    logger.severe("A severe message.");
	} catch (SecurityException e) {
		
		e.printStackTrace();
	} catch (IOException e) {
		
		e.printStackTrace();
	}
		}
	
	public void logIt(){


	    try {
			// TODO Auto-generated method stub
		    Logger logger = Logger.getLogger(LogFormatter.class.getName());
		    logger.setUseParentHandlers(false);
				  
		    LogFormatter formatter = new LogFormatter();
		    // Create console handler and file handler to write log message to console and file
		    ConsoleHandler handler = new ConsoleHandler();
			FileHandler fileHandler = new FileHandler("d:\\LOGTEST\\test_server.txt",true);
		
			// Set format of log to handler
		    handler.setFormatter(formatter);
		    fileHandler.setFormatter(formatter);
		
		    logger.addHandler(handler);
		    logger.addHandler(fileHandler);
		    
		    //Write log by define severity.
		    logger.info("Example of creating custom formatter.");
		    logger.warning("A warning message.");
		    logger.severe("A severe message.");
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	

	
	}

	public static void LogWarning(String message){	    
		
		try {

	    //Write log by define severity.
	    	    
	    logger.warning(message);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
public static void LogNormal(String message){	    
		
		try {
		
	        
	    //Write log by define severity.

	    logger.info(message);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
public static void LogSevere(String message){	    
	
	try {
	
        
    //Write log by define severity.
    	    
    logger.severe(message);
    
	} catch (SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}

}
